119A - Epic Game - CodeForces Solution


implementation *800

Please click on ads to support us..

Python Code:

def gcd(x,y):
    
    m = min(x,y)
    hcf = 0
    
    if x == 0 or y == 0:
        if x != 0:
            return x
        else:
            return y
    else:
        for i in range(1,m+1):
          if x%i == 0 and y%i == 0:
            hcf = i
        
        return hcf
 
a,b,n = map(int,input().split())
active = True
chance = 0
while active:
    t_s = gcd(a,n)
    n = n - t_s
    chance += 1
 
    if n <= 0:
        break
 
    t_as = gcd(b,n)
    n = n - t_as
    chance += 1
 
    if n <= 0:
        break
 
print(0 if chance%2 != 0 else 1)

C++ Code:

#include <bits/stdc++.h>
#include <iomanip>

using namespace std;

#define ll        long long

#define frp(a, b) for(ll i = a; i < b; i++)
#define frn(a, b) for(ll i = a; i > b; i--)

#define V2        vector < vector<ll> > v(n, vector <ll> (n));

#define in(x)     insert(x)
#define pb(x)     push_back(x)
#define full(x)   x.begin(),x.end()

void setup();
void solve();
void test();

int main()
{
	setup();
	// cout << "f" << endl;
	test();
	// solve();
	return 0;
}

void solve()
{
	//cout << "h" << endl;
	ll t; cin >> t;

	while(t--)
	{
		
		ll n; cin >>  n;

        
        vector <ll> v(n);

        frp(0, n) cin >> v[i];

       

	}
}

void test()
{
	ll a, b, n; cin >> a >> b >> n;


	bool simon = true;
	while(true)
	{
		if(n == 0) break;

		if(simon)
		{
			simon = (!simon);

			ll g = __gcd(a, n);
			n -= g;
		}
		else
		{
			simon = (!simon);

			ll g = __gcd(n, b);
			n -= g;
		}

	}

	if(simon) cout << "1" << endl;
	else cout << "0" << endl;

}
void setup()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
#endif
}


Comments

Submit
0 Comments
More Questions

20. Valid Parentheses
746. Min Cost Climbing Stairs
392. Is Subsequence
70. Climbing Stairs
53. Maximum Subarray
1527A. And Then There Were K
1689. Partitioning Into Minimum Number Of Deci-Binary Numbers
318. Maximum Product of Word Lengths
448. Find All Numbers Disappeared in an Array
1155. Number of Dice Rolls With Target Sum
415. Add Strings
22. Generate Parentheses
13. Roman to Integer
2. Add Two Numbers
515. Find Largest Value in Each Tree Row
345. Reverse Vowels of a String
628. Maximum Product of Three Numbers
1526A - Mean Inequality
1526B - I Hate 1111
1881. Maximum Value after Insertion
237. Delete Node in a Linked List
27. Remove Element
39. Combination Sum
378. Kth Smallest Element in a Sorted Matrix
162. Find Peak Element
1529A - Eshag Loves Big Arrays
19. Remove Nth Node From End of List
925. Long Pressed Name
1051. Height Checker
695. Max Area of Island